package old.ships;

import java.util.ArrayList;

public class Communicator {
	
	private ArrayList<String> messageQueue;
	private ArrayList<MapCoordinate> coordQueue;
	private ArrayList<CombatObject> contentQueue;
	private String hostType;
	private CombatObject host;
	
	//must pass type of object and reference to host object upon creation
	public Communicator(CombatObjectEnum type, CombatObject object)
	{
		hostType = type.toString();
		host = object;
		messageQueue = new ArrayList<String>();
		contentQueue = new ArrayList<CombatObject>();
	}
	
	//for messages with content
	private void sendMessage(CombatObject receiver, CombatMessageEnum message, ArrayList<CombatObject> content)
	{
		receiver.communicator.addMessage(message, content);
		
		
	}
	
	//for messages without content
	private void sendMessage(CombatObject receiver, CombatMessageEnum message)
	{
		receiver.communicator.addMessage(message);
		
		
	}
	
	//for messages without content
	public void addMessage(CombatMessageEnum message)
	{
		messageQueue.add(message.toString());
		contentQueue.add(null);				
	}
	
	//for messages with content
	public void addMessage(CombatMessageEnum message, ArrayList<CombatObject> content)
	{
		messageQueue.add(message.toString());
		contentQueue.addAll(content);			
	}
	
	//return message at top of queue
	public String getMessage()
	{
		if (messageQueue.isEmpty())
		{
			return "EMPTY";
		}
		else
		{
			String temp1 = messageQueue.get(0);
			messageQueue.remove(0);
			return temp1;
		}
	}
	
	public String getMessage(int index)
	{
		if (messageQueue.isEmpty())
		{
			return "EMPTY";
		}
		else
		{
			String temp = messageQueue.get(index);
			messageQueue.remove(index);
			return temp;
		}
	}
	
	//return content at top of queue
	public CombatObject getContent()
	{
		if (contentQueue.isEmpty())
		{
			return null;
		}
		else
		{
			CombatObject temp1 = contentQueue.get(0);
			contentQueue.remove(0);
			return temp1;
		}
	}
	
	public CombatObject getContent(int index)
	{
		if (contentQueue.isEmpty())
		{
			return null;
		}
		else
		{
			CombatObject temp = contentQueue.get(index);
			contentQueue.remove(index);
			return temp;
		}
	}
	
	
}
